{*
SPDX-FileCopyrightText: © 2021 Olivier Meunier <olivier@neokraft.net>

SPDX-License-Identifier: AGPL-3.0-only
*}
{{ extends "./base" }}
{{ import "/_libs/forms" }}

{{ block title() }}Login{{ end }}

{{ block main() }}
<form action="{{ urlFor(`/login`) }}" method="post" data-controller="login-form"
  data-action="login-form#validate">

  {{ yield formErrors(form=.Form) }}
  {{ yield csrfField() }}
  <input type="hidden" name="redirect" value="{{ .Form.Get(`redirect`).String() }}" />

  {{ yield textField(field=.Form.Get("username"),
                      label="Username or email address",
                      class="max",
                      inputAttrs=attrList(
                        "data-login-form-target", "username",
                        "autocapitalize", "off",
                      ),
  ) }}
  {{ yield passwordField(field=.Form.Get("password"),
                         label="Password",
                         inputAttrs=attrList(
                           "data-login-form-target", "password",
                           "autocomplete", "current-password",
                         ),
  ) }}

  <button class="btn block mt-6 w-full rounded-md" type="submit">Login</button>
</form>

{{- if canSendEmail -}}
  <p class="mt-4 text-center"><a href="{{ urlFor(`/login/recover`) }}" class="link">Forgot your password?</a></p>
{{- end -}}
{{ end }}
